import React, { Component } from 'react'
import TabBar from './TabBar'

class App extends Component {
  constructor() {
    super()
  
    this.state = {
      tabTitle: ['推荐', '新品', '精选'],
      tabsIndex: 0
    }
  }

  getTabsIndex(index) {
    this.setState({tabsIndex: index})
  }
  tabButton(item) {
    return <button>{item}</button>
  }

  render() {
    const { tabTitle, tabsIndex } = this.state
    return (
      <div>
        <TabBar
          title={tabTitle}
          getTabsIndex={index => this.getTabsIndex(index)}
          tabButton= {item => this.tabButton(item)}
        />
        <h2>{ tabTitle[tabsIndex]}</h2>
      </div>
    )
  }
}

export default App